#include <iostream>
#include "node.h"
#include "codegen.h"

extern NBlock* programBlock;
extern int yyparse();

void createCoreFunctions(CodeGenContext& context);

int main(int argc, const char *args[]) {
    extern FILE *yyin;
    if(argc > 1 && (yyin = fopen(args[1], "r")) == NULL)
    {
        printf("can not open %s\n", args[1]);
        exit(1);
    }
    if(yyparse())
    {
	    std::cout << "error\n";
        exit(-1);
    }
    std::cout << programBlock << std::endl;
    
    InitializeNativeTarget();
    InitializeNativeTargetAsmPrinter();
    InitializeNativeTargetAsmParser();

    CodeGenContext context;
    createCoreFunctions(context);
    context.generateCode(*programBlock);
    context.runCode();
    return 0;
}
